<?php defined('SYSPATH') or die('No direct script access.');

/**
 * 团购应用功能接口
 */
class Controller_Pc_Api_V2_Tuan extends Controller_Pc_Api_v2_Base
{
    // 数据请求结果
    private $result;

    /**
     * 参数验证对象
     * @var Request_Api_V2_Tuan
     */
    private $validation;

    /**
     * 团购服务
     * @var Service_Api_Tuan
     */
    private $service;

    public function before()
    {
        parent::before();
        $this->result = array(
            'status' => true,
            'msg' => '操作成功',
            'data' => array()
        );
        $this->validation = Request_Api_V2_Factory::create('tuan', $this->request_params);
        $this->service = new Service_Api_tuan();
    }
    public function after()
    {
        $this->send_datagrams($this->client_info['id'], $this->result, $this->client_info['secret_key']);
    }

    //根据条件获取团购列表
    public function action_get_tuan_list()
    {
        try {
            $this->validation->get_tuan_list()->check();
            $this->request_params['platform_no']=$this->platform_no;
            $data = $this->service->search($this->request_params);
            $this->result['data'] = $data;
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }

    }
    //团购详情
    public function action_get_detail()
    {
        try {
            $this->validation->get_detail()->check();
            $this->request_params['platform_no']=$this->platform_no;
            $data = $this->service->info($this->request_params);
            $this->result['data'] = $data;
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }
    }

    /**
     * 创建订单
     */
    public function action_add_order()
    {
        try {
            $this->validation->add_order()->check();
            $this->request_params['member_info'] = $this->member_info;
            $data = $this->service->create_order($this->request_params);
            $this->result['data'] = $data;
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }
    }

    //查询条件
    public function action_get_query_condition()
    {
        try {
            $data = $this->service->query_condition();
            $this->result['data'] = $data;
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }
    }
    //搜索
    public function action_general_query()
    {
        try {
            $this->validation->general_query()->check();
            $data = $this->service->search($this->request_params);
            $this->result['data'] = $data;
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }
    }

    //获取最近可订日期
    public function action_get_can_book_date()
    {
        try {
            $this->validation->get_can_book_date()->check();
            $data = $this->service->get_can_book_date($this->request_params);
            $this->result['data'] = $data;
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }

    }

    /**
     * 获取日历
     */
    public function action_get_calendar()
    {
        try {
            $this->validation->get_calendar()->check();
            $data = $this->service->get_calendar($this->request_params);
            $this->result['data'] = $data;
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }
    }
    /**
     * @function 获取快递费用
     */
    public function action_get_express_fee()
    {
        try {
            $data = $this->service->get_express_fee($this->request_params);
            $this->result['data'] = $data;
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }

    }
}
